package com.eec.AOP.responsibility;

import com.eec.AOP.Chain;
import com.eec.spring.ioc.IOCContainer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author LeeC
 * @description
 * @date 2025/8/15
 * @PACKAGE_NAME com.eec.AOP.responsibility
 */
public class ResponsibilityAfter extends BaseResponsibility implements Responsibility  {
    // 存放的是哪个 注解的 calss 对象
    public ResponsibilityAfter(Class<?> CLASS, Method method, Class<?> aspectClass) {
        super.annotationClass = CLASS;
        super.method = method;
        super.aspectClass = aspectClass;
    }
    @Override
    public Object invoke(Chain chain) {
        Object proceed = chain.proceed();

        Object singleBean = IOCContainer.getSingleBean(aspectClass);
        // 这里的参数可以进行修改这里 简易实现AOP
        Object[] args = null;
        try {
            method.invoke(singleBean,args);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return proceed;
    }

    @Override
    public Class<?> getAnnotationClass() {
        return super.annotationClass;
    }

    @Override
    public void setAnnotationClass(Class<?> annotationClass) {
        super.annotationClass = annotationClass;
    }
}
